<?php
namespace App\Providers;

use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Database\Events\StatementPrepared;

class EventServiceProvider extends ServiceProvider
{

    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'App\Events\Event' => [
            'App\Listeners\EventListener'
        ],
        'App\Events\Trade\Supply\PublishEvent' => [
            'App\Listeners\Trade\Supply\PublishListener'
        ],
        'App\Events\Trade\Supply\LeaveEvent' => [
            'App\Listeners\Trade\Supply\LeaveListener'
        ],
        'App\Events\Trade\Supply\RefreshEvent' => [
            'App\Listeners\Trade\Supply\RefreshListener'
        ],
        'App\Events\Trade\Supply\ReportEvent' => [
            'App\Listeners\Trade\Supply\ReportListener'
        ],
        'App\Events\Trade\Supply\CollectionEvent' => [
            'App\Listeners\Trade\Supply\CollectionListener'
        ],
        'App\Events\Trade\Shop\CollectionEvent' => [
            'App\Listeners\Trade\Shop\CollectionListener'
        ],
        'App\Events\Trade\Demand\PublishEvent' => [
            'App\Listeners\Trade\Demand\PublishListener'
        ],
        'App\Events\Trade\Demand\LeaveEvent' => [
            'App\Listeners\Trade\Demand\LeaveListener'
        ],
        'App\Events\Trade\Demand\RefreshEvent' => [
            'App\Listeners\Trade\Demand\RefreshListener'
        ],
        'App\Events\Trade\Demand\ReportEvent' => [
            'App\Listeners\Trade\Demand\ReportListener'
        ],
        'App\Events\Trade\Demand\CollectionEvent' => [
            'App\Listeners\Trade\Demand\CollectionListener'
        ]
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();
        
        // 修改 PDO Fetch Mode
        Event::listen(StatementPrepared::class, function ($event) {
            $event->statement->setFetchMode(\PDO::FETCH_ASSOC);
        });
    }
}
